-- Copyright (c) 2006 Frank Buss (fb@frank-buss.de)
-- See license.txt for license
--
-- This provides a PCA9555 on address 0x26 for the Spartan3 Starter Kit.
-- The high nibble of port 0 are the switches.
-- Reset is BTN3.
-- Write to port 1 for updating the 8 LEDs.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity spartan3_test is
	port(
		clock_50mhz: in std_logic;
		scl: in std_logic;
		sda: inout std_logic;
		led: inout unsigned(7 downto 0);
		button: in std_logic;
		switch: inout unsigned(7 downto 0));
end entity spartan3_test;

architecture rtl of spartan3_test is

component pca9555 is
	generic(
		clock_frequency: natural := 50e6;
		address: unsigned(6 downto 0) := b"0100110");
	port(
		clock: in std_logic;
		reset: in std_logic;
		scl: in std_logic;
		sda: inout std_logic;
		port0: inout unsigned(7 downto 0);
		port1: inout unsigned(7 downto 0));
end component pca9555;

	-- PCA9555 signals
	signal port0: unsigned(7 downto 0);
	signal port1: unsigned(7 downto 0);

begin

	pca9555_instance: pca9555
		generic map(
			clock_frequency => 50e6,
			address => b"0100110")
		port map(
			clock => clock_50mhz,
			reset => button,
			scl => scl,
			sda => sda,
			port0 => switch,
			port1 => led);

end architecture rtl;
